/**
 * Created by yanlin on 2017/10/21.
 */

Ext.onReady(function () {
    var tree = new Ext.tree.TreePanel({
        //region: 'west',
        // True表示为面板是可收缩的，并自动渲染一个展开/收缩的轮换按钮在头部工具条
        collapsible: false,
        width: 200,
        height: 670,
        border: true,// 表框
        autoScroll: true,// 自动滚动条
        animate: true,// 动画效果
        rootVisible: true,// 根节点是否可见
        split: true,
        root: new Ext.tree.AsyncTreeNode({
            text: '宁波市水文站',
            id: '00',
            expanded: true,
            children: [{
                text: '行政区划',
                id: "xzqh",
                leaf: false,
                expanded: true,
                loader:new Ext.tree.TreeLoader({
                    dataUrl: '/qtIndex/xzqhxxTree.action'
                }),
                listeners: {
                    click: function (node) {
                        if(node.isExpanded()){
                            node.collapse();
                        }else{
                            node.expand();
                        }
                    }
                }
            }, {
                text: '管理单位',
                id: "gldw",
                leaf: false,
                loader:new Ext.tree.TreeLoader({
                    dataUrl: '/qtIndex/gldwTree.action'
                }),
                listeners: {
                    click: function (node) {
                        if(node.isExpanded()){
                            node.collapse();
                        }else{
                            node.expand();
                        }
                    }
                }
            }]

        })

    });
    tree.getRootNode().expand();
    tree.on("click", function (node) {
        if(node.id != 'xzqh' && node.id != 'gldw') {
            document.getElementById("i_frame").src = '/qtIndex/sskzmInfo.action?id=' + node.id;
        }
    });

    var treeTab = new Ext.Panel({
        title: '',
        region: 'west',
        margins: '0 5 0 0',
        collapsible: true,
        layout: {
            type: 'vbox',
            align: 'stretch' //拉伸使其充满整个父容器
        },
        width: 200,
        height: 100,
        items: [
            tree
        ]
    });

    var tab = new Ext.TabPanel({
        activeTab: 11,
        region: "center",
        deferredRender: true,
//        autoDestroy:false,
//        CloseAction:'hide',
        items: [
            {
                title: '基本信息',
//                closable:true,
                id: 11,
                html: '<iframe id="i_frame" frameborder="0"  scrolling="no" src="/qtIndex/sskzmInfo.action?id=00" width="100%" height="100%" ></iframe>'
            }
        ]
    });


    var viewport = new Ext.Panel({
        renderTo: 'content',
        region: 'center',
        width: 1356,
        height: 700,
        layout: 'border',
        items: [treeTab, tab]
    });

});